using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication4
{
    public class Distance
    {
        double distance;

        public Distance(int originX, int originY, int destinationX, int destinationY)
        {
            double x, y;
            x = System.Math.Abs(originX - destinationX);
            y = System.Math.Abs(originY - destinationY);

            x = x * x;
            y = y * y;

            distance = System.Math.Sqrt(x + y);
        }

        public TimeSpan TravelTime(Unit unit)
        {
            TimeSpan time = new TimeSpan(Convert.ToInt64(distance * unit.timePerField.Ticks));

            // round to nearest second
            if (time.Milliseconds > 500)
            {
                time = time.Add(new TimeSpan(0,0,0,0,1000 - time.Milliseconds));
            } else {
                time = time.Subtract(new TimeSpan(0,0,0,0,time.Milliseconds));
            }

            return time;
        }

    }
}
